package com.jxsm.service.impl;

import com.jxsm.dao.ExportDao;
import com.jxsm.dao.PackingListDao;
import com.jxsm.page.Page;
import com.jxsm.pojo.Export;
import com.jxsm.pojo.PackingList;
import com.jxsm.service.PackingListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * Created by Administrator on 2016/11/15.
 */
@Service
public class PackingListServiceimpl implements PackingListService {
    @Autowired
    private PackingListDao packingListDao;
    @Autowired
    private ExportDao exportDao;
    public void insert(PackingList packingList) {
        packingList.setId(UUID.randomUUID().toString());
        packingList.setState(1);
        String _exportIds="";
        String _exportNos="";
        String [] _s=packingList.getExportIds().split(",");
        for(int i=0;i<_s.length;i++){
            String [] _tmp=_s[i].split("\\|");
            _exportIds+=_tmp[0];
            _exportNos+=_tmp[1];
        }
        packingList.setExportIds(_exportIds);
        packingList.setExportNos(_exportNos);
        System.out.println(packingList);
        packingListDao.insert(packingList);
    }

    public void update(PackingList entity) {
        packingListDao.update(entity);
    }

    public void deleteById(Serializable id) {
        packingListDao.deleteById(id);
    }

    public void delete(Serializable[] id) {
        packingListDao.delete(id);
    }

    public List<PackingList> findPage(Page page) {
        return packingListDao.findPage(page);
    }

    public List<PackingList> find(Map map) {
        return packingListDao.findAll(map);
    }

    public PackingList get(Serializable id) {
        return packingListDao.get(id);
    }

    public void start(Serializable[] id) {

    }

    public void stop(Serializable[] id) {

    }
    //拼接管理关系的html
    public String getDivData(String [] exportid){
        StringBuffer stringBuffer=new StringBuffer();
    for (int i=0;i<exportid.length;i++){
        Export export=exportDao.get(exportid[i]);
        String exportNos= export.getCustomerContract();
       stringBuffer.append("<input type=\"checkbox\"  name=\"exportIds\" checked value=\"").append(exportid[i]).append("|").append(exportNos).append("\" class=\"input\" />");
        stringBuffer.append(exportNos).append("&nbsp;&nbsp;");
    }
        return stringBuffer.toString();
    }
}
